import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class Solution645 {
    public int[] findErrorNums(int[] nums) {
        Set<Integer> set=new HashSet<>();
        int target=-1;
        int sum=0;
        for (int num : nums) {
            if (set.contains(num)){
                target=num;
            }
            set.add(num);
            sum=sum+num;
        }
        int n=nums.length;
        int target2=(n+1)*n/2-(sum-target);
        return new int[]{target,target2};
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(new Solution645().findErrorNums(new int[]{1,2,2,4})));
    }
}
